package com.tianyalei.wolf.mddesignlib.adater;

/**
 * Created by wolf on 2016/4/8.
 */

import android.content.Context;

import com.zhy.base.adapter.recyclerview.CommonAdapter;

import java.util.List;

/**
 * RecycleView的adapter的封装
 */
public abstract class RecyclerAdapter<T> extends CommonAdapter<T> {

    public RecyclerAdapter(Context context, List<T> datas, int layoutId) {
        super(context, layoutId, datas);
    }

    public void setData(List<T> datas) {
        mDatas.clear();
        mDatas.addAll(datas);
        notifyDataSetChanged();
    }

    public void remove(int position) {
        mDatas.remove(position);
        notifyItemRemoved(position);
    }

    public void addOneData(int position, T t) {
        mDatas.add(position, t);
        notifyItemInserted(position);
    }

    /**
     * 给加载更多用的
     *
     * @param data
     */
    public void addRangeData(List<T> data) {
        int start = mDatas.size() - 1;
        if (start < 0) {
            start = 0;
        }
        mDatas.addAll(data);
        notifyItemRangeChanged(start, data.size());
    }

    public void removeAll() {
        mDatas.clear();
        notifyDataSetChanged();
    }

    public List<T> getDatas() {
        return mDatas;
    }
}